<template>
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
        </a-form>
      </div>
      <!-- 查询区域-END -->
  
      <!-- 操作按钮区域 -->
      <div class="table-operator">
  
      </div>
  
      <!-- table区域-begin -->
      <div>
  
        <a-table
          ref="table"
          size="middle"
          :scroll="{x:scrollX}"
          :components="draggableComponent"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          :customRow="customRow"
          @change="handleTableChange">
          <template slot="status" slot-scope="status">
            <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
          </template>
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
            <img
              v-else
              :src="getImgView(text)"
              height="25px"
              alt=""
              style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
            <a-button
              v-else
              :ghost="true"
              type="primary"
              icon="download"
              size="small"
              @click="downloadFile(text)">
              下载
            </a-button>
          </template>
  
        </a-table>
      </div>
      <a-modal
        :maskClosable="false"
        title="框架合同详情"
        :width="1350"
        :bodyStyle="{
          padding: '0 24px'
        }"
        :visible="visible"
        @cancel="handleCancel"
        cancelText="关闭">
          <a-card
            :bordered="false"
            :bodyStyle="{
              padding: '10px 24px'
            }">
              <ContractApplicationListDetailForm ref="realForm" :disabled="true" normal></ContractApplicationListDetailForm>
              <common-flow-list v-if="model.bpmStatus !== '1'" :formData="formData"></common-flow-list>
          </a-card>
          <template slot="footer">
            <a-button @click.stop="()=>{visible=false}">关闭</a-button>
          </template>
        </a-modal>
      <!-- <erp-omc-contract-manager-final-modal ref="modalForm" @ok="modalFormOk"></erp-omc-contract-manager-final-modal> -->
    </a-card>
  </template>
  
  <script>
  
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
  import { getAction } from '@/api/manage'
  import ErpOmcContractManagerFinalModal from './modules/ErpOmcContractManagerFinalModal'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import ContractApplicationListDetailForm from './modules/ContractApplicationListDetailForm'
  import CommonFlowList from '@/views/components/CommonFlowList.vue' // 审批历史流程列表组件

  export default {
    name: 'ErpApplicationRecord',
    mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ContractApplicationListDetailForm,
      ErpOmcContractManagerFinalModal,
      CommonFlowList
    },
    props: {
      disabledButton: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        description: '合同档案管理管理页面',
        // 表头
        columns: [],
        model:{},
        flowCode:'',
        // 列设置
        settingColumns: [],
        visible:false,
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '合同编号',
            align: 'center',
            dataIndex: 'htbh',
            width: 151,
            ellipsis: true
          },
          {
            title: '合同名称',
            align: 'center',
            dataIndex: 'htmc',
            width: 106,
            ellipsis: true
          },
        //   {
        //     title: '项目编号',
        //     align: 'center',
        //     dataIndex: 'xmbh',
        //     width: 174,
        //     ellipsis: true
        //   },
        //   {
        //     title: '项目名称',
        //     align: 'center',
        //     dataIndex: 'xmmc_dictText',
        //     width: 140,
        //     ellipsis: true
        //   },
          {
            title: '业绩归属年度',
            align: 'center',
            dataIndex: 'yjgsnd_dictText',
            width: 104,
            ellipsis: true
          },
          {
            title: '签订日期',
            align: 'center',
            dataIndex: 'qdrq',
            width: 91,
            ellipsis: true,
            customRender: function (text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '合同类型',
            align: 'center',
            dataIndex: 'htlx_dictText',
            width: 75,
            ellipsis: true
          },
          {
            title: '本次合同额(元)',
            align: 'center',
            dataIndex: 'bchte',
            width: 113,
            ellipsis: true
          },
          {
            title: '签订单位',
            align: 'center',
            dataIndex: 'qddw_dictText',
            width: 190,
            ellipsis: true
          },
          {
            title: '业主单位',
            align: 'center',
            dataIndex: 'yzdw_dictText',
            width: 75,
            ellipsis: true
          },
          {
            title: '经营团队',
            align: 'center',
            dataIndex: 'jytd_dictText',
            width: 240,
            ellipsis: true
          },
          {
            title: '申请人',
            align: 'center',
            dataIndex: 'createBy_dictText',
            ellipsis: true,
            width: 100
          },
          {
            title: '申请部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
            ellipsis: true,
            width: 100
          },
          {
            title: '类型',
            align: 'center',
            dataIndex: 'lx_dictText',
            ellipsis: true,
            width: 100
          },
          {
            title: '审核状态',
            align: 'center',
            dataIndex: 'bpmStatus_dictText',
            width: 60,
            ellipsis: true
          }
        ],
        url: {
          list: '/api/erp/omc/contractmanager/erpOmcContractManager/list',
          list0: '/api/erp/omc/contractmanager/erpOmcContractManager/list?htbh=',
          delete: '/api/erp/omc/contractmanager/erpOmcContractManager/delete',
          deleteBatch: '/api/erp/omc/contractmanager/erpOmcContractManager/deleteBatch',
          exportXlsUrl: '/api/erp/omc/contractmanager/erpOmcContractManager/exportXls',
          importExcelUrl: 'api/erp/omc/contractmanager/erpOmcContractManager/importExcel',
          queryById: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/queryById'
        },
        dictOptions: {},
        superFieldList: [],
        disableMixinCreated: true,
        colsettings: 'ErpOmcContractManagerList2:colsettings'
      }
    },
    watch: {
      $route(to, from) {
        getAction(this.url.queryById, { id: this.$route.params.id }).then(res => {
          if (res.success) {
            // this.url.list = this.url.list0 + res.result.htbh
            this.loadData();
          }
        })
      }
    },
    created() {
      this.getSuperFieldList();
      getAction(this.url.queryById, { id: this.$route.params.id }).then(res => {
        if (res.success) {
          // this.url.list = this.url.list0 + res.result.htbh
          this.loadData();
        }
      })
      this.initColumns();
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams() // 查询条件
        params.htlx = 3
        params.bpmStatus = '2,3'
        params.caId = this.$route.params.id
        
        this.loading = true
        getAction(this.url.list, params).then(res => {
          if (res.success) {
            // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            // 判断是否当前页没有数据且不为第一页
            if (this.dataSource.length == 0 && this.ipagination.current != 1) {
              this.ipagination.current = this.ipagination.current - 1
              this.loadData(this.ipagination.current - 1);
            }
            // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      handleDetail: function (record) {
        this.$nextTick(()=>{
          getAction('/api/erp/omc/contractmanager/erpOmcContractManager/queryById',{ id:record.id }).then((res) => {
          if (res.success) {
            this.visible = true
            const model = res.result
            this.model = model
            this.$nextTick(() => {
              this.$refs.realForm.detailFlag = true
              this.$refs.realForm.edit(model);
            })
            if(record.lx === 1){
              this.flowCode = 'dev_erp_omc_contract_manager_004'
            }
            if(record.lx === 2){
              this.flowCode = 'dev_erp_omc_contract_manager_005'
              // var params = { flowCode: 'dev_erp_omc_contract_manager_005', dataId: record.id };// 查询条件
            }
            // // 查询流程
            let params = { flowCode: this.flowCode, dataId: this.model.id };// 查询条件
            this.viewTrack(params);
          }
        })
        })
 
      },
      handleCancel () {
        this.visible = false
      },
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({ type: 'string', value: 'handlerId', text: '经办人编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'handlerDeptId', text: '经办人部门ID', dictCode: '' })
        fieldList.push({ type: 'string', value: 'handlerDeptCode', text: '经办人部门编码', dictCode: '' })
        fieldList.push({ type: 'string', value: 'delFlag', text: '是否已删除', dictCode: '' })
        fieldList.push({ type: 'string', value: 'htbh', text: '合同编号', dictCode: '' })
        fieldList.push({ type: 'int', value: 'htlx', text: '合同类型', dictCode: '' })
        fieldList.push({ type: 'string', value: 'jytd', text: '经营团队', dictCode: '' })
        fieldList.push({ type: 'string', value: 'htmc', text: '合同名称', dictCode: '' })
        fieldList.push({ type: 'string', value: 'xmmc', text: '项目名称', dictCode: '' })
        fieldList.push({ type: 'int', value: 'sfyz', text: '', dictCode: '' })
        fieldList.push({ type: 'string', value: 'yzdw', text: '业主单位', dictCode: '' })
        fieldList.push({ type: 'string', value: 'qddw', text: '签订单位', dictCode: '' })
        fieldList.push({ type: 'string', value: 'yzlx', text: '印章类型', dictCode: '' })
        fieldList.push({ type: 'int', value: 'yyfs', text: '用印份数', dictCode: '' })
        fieldList.push({ type: 'string', value: 'xmcjr', text: '项目承接人', dictCode: '' })
        fieldList.push({ type: 'int', value: 'glskht', text: '关联收款合同', dictCode: '' })
        fieldList.push({ type: 'date', value: 'qdrq', text: '签订日期' })
        fieldList.push({ type: 'string', value: 'lxr', text: '联系人', dictCode: '' })
        fieldList.push({ type: 'string', value: 'lxfs', text: '联系方式', dictCode: '' })
        fieldList.push({ type: 'int', value: 'yjgsnd', text: '业绩归属年度', dictCode: '' })
        fieldList.push({ type: 'int', value: 'skhte', text: '收款合同额', dictCode: '' })
        fieldList.push({ type: 'date', value: 'fwqx', text: '服务期限' })
        fieldList.push({ type: 'string', value: 'yf', text: '乙方', dictCode: '' })
        fieldList.push({ type: 'string', value: 'bchtedx', text: '本次合同额大写', dictCode: '' })
        fieldList.push({ type: 'string', value: 'skhtedx', text: '收款合同额大写', dictCode: '' })
        fieldList.push({ type: 'string', value: 'skhtmc', text: '收款合同名称', dictCode: '' })
        fieldList.push({ type: 'int', value: 'bchte', text: '本次合同额', dictCode: '' })
        fieldList.push({ type: 'string', value: 'jf', text: '甲方', dictCode: '' })
        fieldList.push({ type: 'string', value: 'xmbh', text: '项目编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'status', text: '状态', dictCode: '' })
        fieldList.push({ type: 'int', value: 'lx', text: 'lx', dictCode: '' })
        fieldList.push({ type: 'string', value: 'bz', text: 'bz', dictCode: '' })
        fieldList.push({ type: 'string', value: 'yjxx', text: 'yjxx', dictCode: '' })
        fieldList.push({ type: 'string', value: 'xgfj', text: 'xgfj', dictCode: '' })
        this.superFieldList = fieldList
      }
    }
  }
  </script>
  <style scoped>
  @import '~@assets/less/common.less';
  </style>
  